class EnglishHybridSearch:
    def __init__(self, db_path: str, qwen_api_url: str = None):
        self.db_path = db_path
        self.qwen_api_url = qwen_api_url

        # 初始化英文向量搜索
        self.vector_searcher = EnglishVectorSearch(db_path)

        # 初始化英文关键词搜索
        self.keyword_searcher = EnglishSimilaritySearch(db_path, qwen_api_url)

    def search_most_similar(self, product_names: List[str], top_k: int = 5) -> Dict[str, List[Tuple[Dict, float]]]:
        """英文混合搜索"""
        results = {}

        for query in product_names:
            print(f"Searching for: {query}")

            # 第一阶段：英文向量快速搜索
            vector_results = self.vector_searcher.search_similar_english(query, top_k * 5)

            if not vector_results:
                results[query] = []
                continue

            # 提取候选产品
            candidates = [product for product, score in vector_results if score > 0.2]

            if not candidates:
                # 如果向量结果不理想，使用关键词搜索
                candidates = self.keyword_searcher.fast_english_prefilter(query, top_n=30)

            # 第二阶段：Qwen精排
            if self.qwen_api_url and len(candidates) > 0:
                scored_results = self.keyword_searcher.qwen_similarity_batch(query, candidates[:20])
                final_results = scored_results[:top_k]
            else:
                # 使用向量相似度结果
                final_results = vector_results[:top_k]

            results[query] = final_results

        return results